package com.threadlocal;
class Tools{
	public static ThreadLocal<String> tl = new ThreadLocal<>();
}
class ThreadA extends Thread{
	@Override
	public void run() {
		try {
			for(int i=0; i<100; i++){
				Tools.tl.set("ThreadA"+(i+1));
				System.out.println("ThreadA get Value="+ Tools.tl.get());
				Thread.sleep(200);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
class ThreadB extends Thread{
	@Override
	public void run() {
		try {
			for(int i=0; i<100; i++){
				Tools.tl.set("ThreadB"+(i+1));
				System.out.println("ThreadB get Value="+ Tools.tl.get());
				Thread.sleep(200);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
public class Run2 {

	public static void main(String[] args) {
		try {
			ThreadA a = new ThreadA();
			ThreadB b = new ThreadB();
			a.start();
			b.start();
			for(int i=0; i<100;i++){
				Tools.tl.set("Main"+(i+1));
				System.out.println("Main get Value="+ Tools.tl.get());
				Thread.sleep(200);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
